
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { apiDictDetail,apiUsersinterface } from '../api.js'
// 定义 Store
export const useMemberStore = defineStore(
  'member',
  () => {
    // 会员信息
    const token = ref()
    const userId=ref("")
    const userName=ref("")
    const userInfo=ref()
    //危废登记部门数据
    const deptMap=ref([])
    //危险废物类别和所属部门的数据
    const typeAndDep=ref({})
   //申请转运中转运危废下的table别表
   const stateTable=reactive({
    rows: [],//新增领料中选中材质或成品勾选保存赋值给领料要求的数据
    //我的申请中select_register_by_ids接口的数据
    temporaryData:[]
  })
  //首页中审批的数据
  const approval=ref({})
  // 我的申请点击每一条数据查看详情
  const ApplyViewing=ref({})
  //我的登记点击每一条数据查看详情
  const RegisterObjViewing=ref({})
  //查询中类型或部门中的已转运详情
  const QueryTransferDetails=ref({})
  //数据看板点击详情传递0或1
  const currentNub=ref(0)
  //按钮点击loading和disabled效果
  const boleanDisabled=ref(false)
  //tab页查询页面部门和类型的数据
  const searchLists=ref([])
  //pdf预览地址
  const srcURL=ref("")
  //领料类型
  const pickTypeLists=ref([])
  const apiDictfnDetail=async (dictName)=>{
    const res = await apiDictDetail(dictName);
      if (res) {
        pickTypeLists.value = res.content;
      } else {
        pickTypeLists.value = [];
      }
  }
  //领料人
  const saleslLists=ref([])
  const salespersonListsfn=async ()=>{
    const res = await apiUsersinterface();
      if (res) {
        saleslLists.value = (res || []).reduce((pre, next) => {
          if (next.salesmanCode) {
            pre.push({
              label: next.nickName,
              value: next.id,
              salesmanCode: next.salesmanCode,
            });
          }
          return pre;
        }, []);
      } else {
        saleslLists.value = [];
      }
  }
  //选中材质，规格型号，炉号的时候保存的值，需要给上一个页面使用
  const zemId=ref("")
  const zemName=ref("")
  const from_Page=ref("")
  //新增领料中点击选中存储领取要求数据
  const lingliaoyaoqiu=ref([])
  //领料列表数据
  const currentmaterialtable=ref({})
  //退库和我的工序列表数据
  const currenttukutable=ref({})
  //生产领料，领料确认，出库确认当前数据的id
  const tableId=ref("")
  //库房数据
  const warehouseLists=ref([])
  const apiDictfnwarehouse=async (dictName)=>{
    const res = await apiDictDetail(dictName);
      if (res) {
        warehouseLists.value = res.content;
      } else {
        warehouseLists.value = [];
      }
  }
  //库位数据
  const locationLists=ref([])
  const apiDictfnlocation=async (dictName)=>{
    const res = await apiDictDetail(dictName);
      if (res) {
        locationLists.value = res.content;
      } else {
        locationLists.value = [];
      }
  }
  const PrinterName=ref("");
  //打印标签模板
  const tempLists=ref([]);
  const apiDicttemlocation=async (dictName)=>{
    const res = await apiDictDetail(dictName);
      if (res) {
        tempLists.value = res.content;
      } else {
        tempLists.value = [];
      }
  }
  //打印标签品名
  const pinnameLists=ref([]);
  const apiDictpinnlocation=async (dictName)=>{
    const res = await apiDictDetail(dictName);
      if (res) {
        pinnameLists.value = res.content;
      } else {
        pinnameLists.value = [];
      }
  }
  //打印标签标准
  const biaozhunLists=ref([]);
  const apiDictbiaonlocation=async (dictName)=>{
    const res = await apiDictDetail(dictName);
      if (res) {
        biaozhunLists.value = res.content;
      } else {
        biaozhunLists.value = [];
      }
  }
    return {
      token,
      userId,
      userName,
      userInfo,
      deptMap,
      stateTable,
      approval,
      typeAndDep,
      ApplyViewing,
      RegisterObjViewing,
      currentNub,
      boleanDisabled,
      searchLists,
      QueryTransferDetails,
      srcURL,
      pickTypeLists,
      apiDictfnDetail,
      saleslLists,
      salespersonListsfn,
      zemId,
      zemName,
      from_Page,
      lingliaoyaoqiu,
      currentmaterialtable,
      currenttukutable,
      tableId,
      warehouseLists,
      apiDictfnwarehouse,
      locationLists,
      apiDictfnlocation,
      PrinterName,
      tempLists,
      apiDicttemlocation,
      pinnameLists,
      apiDictpinnlocation,
      biaozhunLists,
      apiDictbiaonlocation,
    }
  },
  {
    // 网页端配置
    // persist: true,
    // 小程序端配置
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
      },
    },
  },
)
